<?php

class RoleModel extends CommonModel {

    protected $_validate = array(
        array('mc', '', '角色名称已经存在！', 0, 'unique', 1),
        array('mc', 'checkMc', '角色名称已经存在！', 1, 'callback',2),
    );

    function checkMc(){
        $old_mc = $_REQUEST['old_mc'];
        $mc = $_REQUEST['mc'];
        if ($old_mc != $mc){
            $count = $this->where('mc="'.$mc.'"')->count();
            if ($count > 0){
                return false;
            }
        }else{
            return true;
        }
    }
    function get_list() {
        $res = $this->Table(C('DB_PREFIX') . 'role a')->join(C('DB_PREFIX') . 'role as b ON b.pid = a.id')
                ->group('a.id')->order('pid,sort_order ASC')
                ->field('a.*,count(b.id) AS has_children')
                ->select();
        return $res;
    }

}

?>
